package com.hellpro.lolbox.home.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.bean.ZXZp;

import java.util.ArrayList;
import java.util.List;

/**
 * Package_Name: com.hellpro.lolbox.home.presenter
 * Description :
 * author: HellPermanent
 * date:  2016/10/22 1:16
 * remarks：
 */
public class ZXRecycleAdapter extends RecyclerView.Adapter<ZXRecycleAdapter.MyViewHolder>{
private List<ZXZp.DataBean> mList;
    private Context context;
    public ZXRecycleAdapter(){
        mList = new ArrayList<>();
    }

    public  void reMove(){
        mList.removeAll(mList);
    }
    public  void setData(List<ZXZp.DataBean> list, Context context){

        mList.addAll(list);
        this.context =context;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.zxrecyclea_list, parent, false);
        return new MyViewHolder(view) ;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String coverUrl = mList.get(position).getCoverUrl();

        ViewGroup.LayoutParams layoutParams = holder.photo.getLayoutParams();
     layoutParams.height= 3*Integer.parseInt(mList.get(position).getCoverHeight());
      //  layoutParams.width = Integer.parseInt(mList.get(position).getCoverWidth());
        holder.photo.setLayoutParams(layoutParams);
        Glide.with(context).load(coverUrl).into(holder.photo);
        holder.piscum.setText("点击"+" " +mList.get(position).getPicsum());
        holder.textView.setText(mList.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return mList!=null?mList.size():0;
    }
    static class  MyViewHolder extends  RecyclerView.ViewHolder implements View.OnClickListener{

        private final ImageView photo;
        private final TextView piscum;
        private final TextView textView;

        public MyViewHolder(View itemView) {
            super(itemView);
            photo = (ImageView) itemView.findViewById(R.id.xrecycleview_photo);
            piscum = (TextView) itemView.findViewById(R.id.xrecycleview_picsum);
            textView = (TextView) itemView.findViewById(R.id.xrecycleview_title);
        }

        @Override
        public void onClick(View v) {

        }
    }
}
